package zkclient;

import java.util.concurrent.CountDownLatch;

/**
 * Created by Lenovo on 2018/11/22.
 */
public class OrderServiceTest implements Runnable{

    private static int count = 1000;//并发线程数量
    private static CountDownLatch cdl = new CountDownLatch(count);
    ILock lock = new LockImpl();
    public void run() {
        //创建订单
        createOrderNum();
    }

    public void createOrderNum() {
        lock.lock();
        String orderNum = OrderFactory.GetOrder();
        System.out.println((Thread.currentThread().getName() + "创建了订单号：【" + orderNum
                + "】！"));
        lock.unlock();
    }

    public static void main(String[] args) {
        for (int i = 0; i < count; i++) {
            new Thread(new OrderServiceTest()).start();
            //发令枪里面的数字减一
            cdl.countDown();
        }
    }
}
